<?php
require_once 'includes/Configuration.php';

$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["upload"]["name"]));
if ((($_FILES["upload"]["type"] == "image/gif")
|| ($_FILES["upload"]["type"] == "image/jpeg")
|| ($_FILES["upload"]["type"] == "image/jpg")
|| ($_FILES["upload"]["type"] == "image/png"))
&& ($_FILES["upload"]["size"] < 500000)
&& in_array($extension, $allowedExts))
{
    if ($_FILES["upload"]["error"] > 0)
        echo "Error code: " . $_FILES["upload"]["error"] . "<br>";
    else
    {

    if (file_exists(IMAGE_UPLOAD_FOLDER . $_FILES["upload"]["name"]))
      echo $_FILES["upload"]["name"] . " already exists. ";
    else
      {
      move_uploaded_file($_FILES["upload"]["tmp_name"], IMAGE_UPLOAD_FOLDER . $_FILES["upload"]["name"]);
      echo "Image uploaded!";
      }
    }
  }
else echo "Invalid file";
?> 